<template>
  <div>
      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        bordered
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="contractNo" slot-scope="text, record">
          <a @click="handleDetail(record)">{{text}}</a>
        </template>
      </a-table>
    <sd-contract-modal ref="modalForm" @ok="modalFormOk"/>
  </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import SdContractModal from './modules/SdContractModal'
  import {getAction} from "@/api/manage";
  import '@/assets/less/TableExpand.less'

  export default {
    name: "SdContractTable",
    mixins:[JeecgListMixin],
    components: {
      SdContractModal
    },
    props:{
      initQueryParam:{},
    },
    data () {
      return {
        description: '销售合同管理页面',
        // 表头
        columns: [
          {
            title:'合同编号',
            align:"center",
            dataIndex: 'contractNo',
            scopedSlots: {customRender: 'contractNo'}
          },
          {
            title:'客户',
            align:"center",
            dataIndex: 'customerName'
          },
          {
            title:'合同金额',
            align:"center",
            dataIndex: 'money'
          },
          {
            title:'销售员',
            align:"center",
            dataIndex: 'salesman_dictText'
          },
          {
            title:'销售部门',
            align:"center",
            dataIndex: 'salesDept_dictText'
          },
          {
            title:'纸质合同',
            align:"center",
            dataIndex: 'paperNo'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'签约日期',
            align:"center",
            dataIndex: 'signDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'生效日期',
            align:"center",
            dataIndex: 'effectDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合同名称',
            align:"center",
            dataIndex: 'contractName'
          },
          {
            title:'合同类型',
            align:"center",
            dataIndex: 'contractType_dictText'
          },
          {
            title:'销售类型',
            align:"center",
            dataIndex: 'saleType_dictText'
          },
          {
            title:'截至日期',
            align:"center",
            dataIndex: 'expireDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'负责人',
            align:"center",
            dataIndex: 'owner_dictText'
          },
          {
            title:'负责部门',
            align:"center",
            dataIndex: 'ownerDept_dictText'
          },
          {
            title:'币种',
            align:"center",
            dataIndex: 'currencyNo_dictText'
          },
          {
            title:'签署单位',
            align:"center",
            dataIndex: 'customerSign_dictText'
          },
          {
            title:'客户签约人',
            align:"center",
            dataIndex: 'customerMan'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          }
        ],
        url: {
          list: "/sd/contract/list",
        },
      }
    },
    watch:{
      initQueryParam: {
        deep: true,
        handler(){
          this.loadData();
        }
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        if(Object.keys(this.initQueryParam).find(key => !this.initQueryParam[key])){
          return;
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        Object.assign(this.queryParam, this.initQueryParam);
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>